<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html lang="en">

<head>
    <title>登录</title>
    <!-- meta tags -->
    <meta charset="UTF-8" />
    <link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet" type="text/css" />
    <link href="${pageContext.request.contextPath}/css/fontawesome-all.css" rel="stylesheet" />

</head>

<body>
<h1>强强组合商城</h1>
<div class=" w3l-login-form">
    <h2>登录</h2>
    <form action="#" method="POST" id="loginForm">

        <div class=" w3l-form-group">
            <label>用户名:</label>
            <div class="group">
                <i class="fas fa-user"></i>
                <input type="text" id="accName" class="form-control" placeholder="用户名/学号" required="required" />
            </div>
        </div>
        <div class=" w3l-form-group">
            <label>密码:</label>
            <div class="group">
                <i class="fas fa-unlock"></i>
                <input type="password" id="accPwd" class="form-control" placeholder="密码" required="required" />
            </div>
        </div>
        <div class="forgot">
            <p><input type="checkbox" style="vertical-align: middle; width: 20px;height: 20px">记住我</p>
            <a href="#">忘记密码?</a>
        </div>
        <button type="submit">登录</button>
    </form>
    <p class=" w3l-register-p">没有账号?<a href="register.jsp" class="register"> 立即注册</a></p>
</div>

</body>

<script src="${pageContext.request.contextPath}/assets/js/core/jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/js/layui/layui.js"></script>

<script>
    $(function (){

        layui.use(['form', 'layedit', 'laydate'], function(){
            var form = layui.form
                ,layer = layui.layer
                ,layedit = layui.layedit
                ,laydate = layui.laydate;

            $("#loginForm").submit(function (){
                var stuNo;
                var accName = $("#accName").val();
                if (!isNaN(accName)){
                    stuNo = accName;
                    accName = null;
                }
                var accPwd = $("#accPwd").val();
                var param = {
                    accName:accName,
                    accPwd:accPwd,
                    stuNo:stuNo
                }
                var url = "/login/loginShop";
                $.post(url,param,function (data){
                    if(data.code == 1001){
                        layer.open({
                            type: 1    //类型设置为 1，表示弹出层弹出的内容是 string
                            ,content: '<div style="padding: 20px 100px;">'+ data.msg +'</div>'
                            ,btn: '确定'
                            ,btnAlign: 'c' //按钮居中
                            ,shade: 0 //不显示遮罩
                            ,yes: function(){
                                if(data.role == "admin"){         //如果是管理员，跳转到管理员后台
                                    window.location.href ='jsp/admin/schoolManager.jsp';
                                }else if(data.role == "school"){   //如果是院校审核员，跳转到院校后台
                                    window.location.href ='jsp/school/businessApplyNeedCheck.jsp';
                                }else {                           //否则，跳转到商城首页
                                    window.location.href ='jsp/home/frontend_home.jsp';
                                }
                            }
                        });
                    }else if(data.code == 1002){
                        layer.open({
                            type: 1    //类型设置为 1，表示弹出层弹出的内容是 string
                            ,content: '<div style="padding: 20px 100px;">'+ data.msg +'</div>'
                            ,btn: '确定'
                            ,btnAlign: 'c' //按钮居中
                            ,shade: 0 //不显示遮罩
                            ,yes: function(){
                                layer.closeAll();   //关闭确定弹窗
                                $("#accPwd").val("");
                            }
                        });
                    }
                })
                return false;
            })
        });


    });

</script>

</html>
